﻿using System;
using Spencen.Mobile.Markup;

namespace Spencen.Mobile.UI.Templating
{
    public class DataTemplate : IDataTemplate
    {
        public XamlElement Template { get; set; }

        #region IDataTemplate Members

        public DrawingElement ApplyTemplate( IDrawingHost host, object dataItem )
        {
            if ( Template == null ) return null;

            var templateRenderer = new XamlRenderer( host, dataItem );
            Template.DataContext = dataItem;
            var templateResult = templateRenderer.Render( this, Template );
            return templateResult as DrawingElement;
        }

        #endregion
    }
}
